#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
map <string,bool> server;
map <string,int> index;
bool judge(string s) {
	int cntx=0,cnty=0;
	for(int i=0;i<s.length();++i) {
		if(s[i]=='.') {
			++cntx;
		} else if(s[i]==':') {
			if(cntx==3) {
				++cnty;
			} else {
				return false;
			}
		} else if(!isdigit(s[i])) {
			return false;
		}
	}
	if(cntx!=3||cnty!=1) {
		return false;
	}
	if(s[0]=='0'&&isdigit(s[1])) {
		return false;
	}
	if(!isdigit(s[0])) {
		return false;
	}
	long long x=0;
	for(int i=0;i<s.length();++i) {
		if(s[i]=='.'||s[i]==':') {
			if(x>255) {
				return false;
			}
			x=0;
			if(s[i+1]=='0'&&isdigit(s[i+2])) {
				return false;
			}
			if(!isdigit(s[i+1])) {
				return false;
			}
			if(s[i]==':'&&i+1==s.length()) {
				return false;
			}
		} else {
			x=x*10+s[i]-'0';
		}
	}
	return x<=65535?true:false;
}
int main() {
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;++i) {
		string op,ad;
		cin>>op>>ad;
		if(!judge(ad)) {
			puts("ERR");
			continue;
		}
		if(op=="Server") {
			if(!server[ad]) {
				puts("OK");
				server[ad]=true;
				index[ad]=i;
			} else {
				puts("FAIL");
			}
			continue;
		}
		if(op=="Client") {
			if(!server[ad]) {
				puts("FAIL");
			} else {
				printf("%d\n",index[ad]);
			}
			continue;
		}
	}
	return 0;
}
